package com.city.ajax.pub;

import com.city.domain.city.CityHouseinfo;
import com.city.domain.pub.PubHouseinfo;
import com.city.domain.pub.PubUser;
import com.city.domain.supervise.ImpCategory;
import com.city.domain.supervise.ImpLocation;
import com.city.domain.supervise.ImpOrganization;
import com.city.domain.supervise.ImpThing;
import com.city.service.pub.DeleteService;
import com.city.service.pub.SaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @deprecation: 删除
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-26 10:46
 */
@RestController
@RequestMapping("/ajax/delete")
public class PubDelete {

    @Autowired
    private SaveService saveService;

    @Autowired
    private DeleteService deleteService;


    /**
     * @deprecation: 居民房屋信息失效
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param pubHouseinfo 居民房屋信息
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/houseinfo")
    @Transactional
    @ResponseBody
    public Map<String,String> deletePubHouseinfo(
            @RequestBody PubHouseinfo pubHouseinfo,
            HttpServletResponse response,
            HttpSession session)
    {
        Map<String,String> map = new HashMap<String, String>();

        String loginTel = (String) session.getAttribute("loginTel");
        loginTel = "15708197406";
        //如果没有登陆
        if(loginTel == null){
            map.put("res", "-1");
            map.put("code","未登录,请登录");
        }else {
            if(pubHouseinfo.getId() <= 0){
                map.put("res", "0");
                map.put("code","操作失败");
            }else {
                //更新内容
                pubHouseinfo.setStatus(-1);
                //保存基本信息
                saveService.save(pubHouseinfo);
                map.put("res", "1");
                map.put("code","操作成功");
            }
        }
        return map;
    }

    /**
     * @deprecation: 居民房屋信息测底删除
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/houseinfo-delete")
    @Transactional
    @ResponseBody
    public Map<String,String> deletePubHouseinfoDelete(@RequestBody PubHouseinfo pubHouseinfo,
                                                 HttpServletResponse response,
                                                 HttpSession session){
        Map<String,String> map = new HashMap<String, String>();

        String loginTel = (String) session.getAttribute("loginTel");
        loginTel = "15708197406";
        //如果没有登陆
        if(loginTel == null){
            map.put("res", "-1");
            map.put("code","未登录,请登录");
        }else {
            if(pubHouseinfo.getId() <= 0){
                map.put("res", "0");
                map.put("code","操作失败");
            }else {
                //保存基本信息
                deleteService.delete(pubHouseinfo);
                map.put("res", "1");
                map.put("code","操作已完成");
            }
        }
        return map;
    }

    /**
     * @deprecation: 出租屋信息删除
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/cityhouseinfo-delete")
    @Transactional
    @ResponseBody
    public Map<String,String> deleteCityHouseinfoDelete(@RequestBody CityHouseinfo cityHouseinfo){
        System.out.println(cityHouseinfo);
        Map<String,String> map = new HashMap<String, String>();
        if(cityHouseinfo.getId() <= 0){
            map.put("res", "0");
            map.put("code","操作失败");
        }else {
            deleteService.delete(cityHouseinfo);
            map.put("res", "1");
            map.put("code","操作已完成");
        }
        return map;
    }



    @PostMapping("/keycategory-delete")
    @Transactional
    @ResponseBody
    public Map<String, String> deleteKeyCategoryInfo(@RequestBody ImpCategory impCategory,
                                                   HttpServletResponse response,
                                                   HttpSession session) {
        Map<String, String> map = new HashMap<String, String>();
        deleteService.delete(impCategory);
        map.put("res", "1");
        map.put("code", "完成！");
        return map;
    }


    @PostMapping("/keyorganization-delete")
    @Transactional
    @ResponseBody
    public Map<String, String> deleteKeyOrganizationInfo(@RequestBody ImpOrganization impOrganization,
                                                   HttpServletResponse response,
                                                   HttpSession session) {
        Map<String, String> map = new HashMap<String, String>();
        deleteService.delete(impOrganization);
        map.put("res", "1");
        map.put("code", "完成！");
        return map;
    }

    @PostMapping("/keything-delete")
    @Transactional
    @ResponseBody
    public Map<String, String> deleteKeyThingInfo(@RequestBody ImpThing impThing,
                                                         HttpServletResponse response,
                                                         HttpSession session) {
        Map<String, String> map = new HashMap<String, String>();
        deleteService.delete(impThing);
        map.put("res", "1");
        map.put("code", "完成！");
        return map;
    }


    @PostMapping("/keylocation-delete")
    @Transactional
    @ResponseBody
    public Map<String, String> deleteKeyLocationInfo(@RequestBody ImpLocation impLocation,
                                                  HttpServletResponse response,
                                                  HttpSession session) {
        Map<String, String> map = new HashMap<String, String>();
        deleteService.delete(impLocation);
        map.put("res", "1");
        map.put("code", "完成！");
        return map;
    }
}
